package com.yc.navy.dayfresh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.navy.dayfresh.entity.Fav;
import com.yc.navy.dayfresh.entity.Tag;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author navy
 * @company 源辰信息
 * @date 2024/9/9
 * @email haijunzhou@hnit.edu.cn
 */
public interface TagMapper extends BaseMapper<Tag> {

    @Select("select * from tag where uid = #{uid}")
    // <resultMap> => @Results
    @Results(
            id = "rm1",
            value = {
                    @Result(column = "id", property = "id", id = true),
                    @Result(column = "id", property = "favs",
                            many = @Many(select = "selectFavByTid"))
            }
    )
    List<Tag> selectByUid(int uid);

    @Select("select * from fav a where EXISTS(" +
            " SELECT * from tag_fav b where b.tid=#{tid} and a.id=b.fid)")
    List<Fav> selectFavByTid(int tid);


}
